package definite.Guide.Book.MenuElement.Interface;

import java.awt.Color;
import java.awt.Component;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;

import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JToggleButton;
import javax.swing.MenuElement;
import javax.swing.MenuSelectionManager;
import javax.swing.event.MouseInputListener;

public class JToggleButtonMenuItem extends JToggleButton implements MenuElement {

	Color saveForeground = null;
	private static MenuElement NOSUB_ELEMENT[] = new MenuElement[0];

	public JToggleButtonMenuItem() {
		init();
	}

	public JToggleButtonMenuItem(String label) {
		super(label);
		init();
	}

	public JToggleButtonMenuItem(String label, Icon icon) {
		super(label, icon);
		init();
	}

	public JToggleButtonMenuItem(Action action) {
		super(action);
		init();
	}

	private void init() {
		updateUI();
		setRequestFocusEnabled(false);
		// borrow heavily from basic menu UI
		MouseInputListener mouseInputListener = new MouseInputListener() {

			@Override
			public void mouseMoved(MouseEvent e) {
			}

			@Override
			public void mouseDragged(MouseEvent e) {
			}

			// if mouse realease over this menu , active it
			@Override
			public void mouseReleased(MouseEvent e) {
				MenuSelectionManager menuSelectionManager = MenuSelectionManager
						.defaultManager();
				Point p = e.getPoint();
				if (p.x >= 0 && p.x < getWidth() && p.y >= 0
						&& p.y < getHeight()) {
					menuSelectionManager.clearSelectedPath();

					// component auto handled "Selection" at this point
					doClick(0);
				} else
					menuSelectionManager.processMouseEvent(e);
			}

			@Override
			public void mousePressed(MouseEvent e) {
			}

			@Override
			public void mouseExited(MouseEvent e) {
			}

			// if mouse move over menu item , add it to selected path , it
			// becomes arm
			@Override
			public void mouseEntered(MouseEvent e) {
				MenuSelectionManager menuSelectionManager = MenuSelectionManager
						.defaultManager();
				menuSelectionManager.setSelectedPath(getPath());
			}

			@Override
			public void mouseClicked(MouseEvent e) {
			}
		};
	}

	private MenuElement[] getPath() {

		return null;
	}

	@Override
	public void processMouseEvent(MouseEvent event, MenuElement[] path,
			MenuSelectionManager manager) {
	}

	@Override
	public void processKeyEvent(KeyEvent event, MenuElement[] path,
			MenuSelectionManager manager) {
	}

	@Override
	public void menuSelectionChanged(boolean isIncluded) {
	}

	@Override
	public MenuElement[] getSubElements() {

		return null;
	}

	@Override
	public Component getComponent() {

		return this;
	}

}
